<%@page import="dao.MngAssignment"%>
<%@page import="beans.Assignment"%>
<%@page import="helper.UtilFunction"%>
<%@page import="dao.Student"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<%@page import="beans.ClassBean"%>
<%@page import="java.util.List"%>
<%@page import="dao.MngClass"%>
<%@page import="dao.CheckAccount"%>

<html>
    <head>
        <script language="javascript">
            function delete1()
            {
                return confirm('Do you want delete this record');
            }
        </script>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>Show Class Page</title>
        <style>                        
            table, th, td {
                border: 1px solid #619702;
                border-collapse: collapse;
                width:100% ;
            }
            th, td {
                padding: 5px;
                width: 100px;
            }
            th {
                text-align: center;
            }
        </style>
    </head>
    <body> 
        <h2>List class</h2>
        <%
            if (request.getAttribute("msg") != null) {
        %>
        <font color="green" > <%= request.getAttribute("msg")%> </font>
        <%
            }
             if (request.getAttribute("error") != null) {
        %>
        <font color="red" > <%= request.getAttribute("error")%> </font>
        <%
            }
        
            UtilFunction util = new UtilFunction();
            HttpSession ss_student = request.getSession();
            String student_id = ss_student.getAttribute("acc_id").toString();
            CheckAccount ck = new CheckAccount();
            MngClass mngClass = new MngClass();
            List<ClassBean> listClassStudying = mngClass.listClassByStudentId(student_id);
            List<ClassBean> listClass = mngClass.showClass();
            MngAssignment mngAssign = new MngAssignment();
            List<Assignment> listAssign = null;
        %>       
        <br><br>        
        <table>                
            <tr>
                <th>Staff</th>		
                <th>ClassName</th>
                <th>StartDate</th>
                <th>FinishDate</th>   
                <th>Description</th> 
                <th>Study</th> 

            </tr> 
            <%  if (listClassStudying != null && (listClassStudying.size() > 0)) {
                    for (ClassBean classBeanStudy : listClassStudying) {
                        if (classBeanStudy.getDescription() == null) {
                            classBeanStudy.setDescription("");
                        }
                        if (classBeanStudy.getStart_date() == null) {
                            classBeanStudy.setStart_date("");
                        }
                        if (classBeanStudy.getFinish_date() == null) {
                            classBeanStudy.setFinish_date("");
                        }
            %>
            <tr>
                <th><%= ck.getFullName(classBeanStudy.getAcc_id())%></th>
                <th><%= classBeanStudy.getClass_name()%></th>
                <th><%= classBeanStudy.getStart_date()%></th>
                <th><%= classBeanStudy.getFinish_date()%></th>               
                <th><%= classBeanStudy.getDescription()%></th>
                <th>(Studying)<br>
                    <%
                        listAssign = mngAssign.showAssignByAccountAndClass(student_id, classBeanStudy.getClass_id());
                        if (listAssign != null && (listAssign.size() > 0)) {
                    %>
            <form action="showAssignByClass" method="get">
                <input type="hidden" name="acc_id" value="<%= student_id%>">
                <input type="hidden" name="class_id" value="<%= classBeanStudy.getClass_id()%>">
                <input type="submit" value="Show Assign">
            </form>   
            <%
            } else {
            %>
            No Assign
            <%
                }%>
        </th>
    </tr>   
    <%

            }
        }
        for (ClassBean classBean : listClass) {
            if (classBean.getDescription() == null) {
                classBean.setDescription("");
            }
            if (classBean.getStart_date() == null) {
                classBean.setStart_date("");
            }
            if (classBean.getFinish_date() == null) {
                classBean.setFinish_date("");
            }
            if (listClassStudying != null && (listClassStudying.size() > 0)) {
                if (util.classOutStudent(listClassStudying, classBean.getClass_id())) {

    %>
    <tr>
        <th><%= ck.getFullName(classBean.getAcc_id())%></th>
        <th><%= classBean.getClass_name()%></th>
        <th><%= classBean.getStart_date()%></th>
        <th><%= classBean.getFinish_date()%></th>               
        <th><%= classBean.getDescription()%></th>
        <th>
    <form action="addStudent" method="get">
        <input type="hidden" name="acc_id" value="<%= student_id%>">
        <input type="hidden" name="class_id" value="<%= classBean.getClass_id()%>">
        <input type="submit" value="Join Class">
    </form>   
</th>        
</tr>   
<%
    }
} else {
%>
<tr>               
    <th><%= ck.getFullName(classBean.getAcc_id())%></th>
    <th><%= classBean.getClass_name()%></th>
    <th><%= classBean.getStart_date()%></th>
    <th><%= classBean.getFinish_date()%></th>               
    <th><%= classBean.getDescription()%></th>
    <th>
<form action="addStudent" method="get">
    <input type="hidden" name="acc_id" value="<%= student_id%>">
    <input type="hidden" name="class_id" value="<%= classBean.getClass_id()%>">
    <input type="submit" value="Join Class">
</form>                    
</th>        
</tr>   
<%
        }
    }
%>
</table>
</body>
</html>
